<template>
	<view class="add page c00">
		<view class="bgf7 p12">
			<view class="bgff px14 pb10">
				
				<view class="flex flexC  borb py12" >
					<text class="flex1">所属店铺</text>
					<text class="py3 " >{{selectShop.name}}</text>
				</view>
				
				<view class="flex flexC borb py12">
					<text class="flex1">姓名</text>
					<input v-model="name" class=" aliR py3" placeholder="请输入姓名" />

				</view>
				<view class="flex flexC borb py12">
					<text class="flex1">手机号</text>
					<input v-model="mobile" type="number" class=" aliR  py3" placeholder="请输入手机号" />

				</view>

				<view class="flex flexC  py12" @click="$refs.pop.open()">
					<text class="flex1">角色</text>
					<text class="py3 " >{{role}}</text>
					<text class="arrowR ml3"></text>
				</view>


			</view>
			<view class="flex flexC flexJC py20">
				<view class="aliC py12 w-17 bg41 r40" @click="save">保存</view>
			</view>



		</view>



		<uni-popup ref="pop" type="bottom">
			<view class="popup-content2">
				<button class="popup-btn button" @click="selectRole(0)">保洁员</button>
				<button class="popup-btn button" @click="selectRole(1)">店长</button>
				<button class="popup-btn button" @click="selectRole(2)">投资人</button>

				<view class="popup-btn" @click="$refs.pop.close()">取消</view>
			</view>

		</uni-popup>

		<hFormAlert v-if="tagShow" title="添加标签" placeholder="请输入添加标签" @confirm="confirm" @cancel="cancel"></hFormAlert>


	</view>
</template>

<script>
	import hFormAlert from '@/components/h-form-alert/h-form-alert.vue';

	export default {
		components: {
			hFormAlert
		},
		data() {
			return {
				tagShow: false,
				shop_id: '',
				name: '',
				mobile:'',
				selectShop:null,
				role:"保洁员"
			};
		},
		onLoad(option) {

			var shop = option.selectShop;
			this.selectShop = JSON.parse(shop);
		},

		onShow() {

		},
		methods: {



			selectRole(index){
				this.$refs.pop.close();
				if(index == 0){
					this.role = "保洁员";
				}else if(index == 1){
					this.role = "店长";
				}else if(index ==2 ){
					this.role = "投资人";	
				}

			},


			save() {

				if (this.name == '') {

					uni.showToast({
						title: "请填姓名",
						icon: 'none'
					})
					return;
				}


				if (this.mobile == '') {

					uni.showToast({
						title: "请填写手机号",
						icon: 'none'
					})
					return;
				}


				let param = {
					shop_id: this.selectShop.id,
					username: this.name,
					mobile:this.mobile,
					role:this.role
				};
				let that = this;
				this.$api.addStaff(param).then(res => {

					if (res.code == 1) {
						uni.showModal({
							title: "添加提示",
							content: "添加成功",
							showCancel: false,
							complete() {
								uni.navigateBack({
									delta: 1
								})
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.add {
		.w48 {
			width: 96rpx;
			height: 96rpx;
		}

		.imgbox {
			width: 164rpx;
			height: 164rpx;
			background-color: #E8E8E8;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}

			.del {
				width: 36rpx;
				height: 36rpx;
				background: rgba(181, 180, 180, .8);
				position: absolute;
				top: -12rpx;
				right: -12rpx;
			}
		}
	}

	.popup-content2 {
		background: #FFFFFF;

		.popup-btn {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
		}

		.button {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
			font-size: 11pt;
		}

		button::after {
			border: none;
		}

		.pt20 {
			border-bottom: 20rpx solid #f5f5f5;
		}
	}
</style>
